<template>
  <div>
    <el-dialog title="批量添加" width="" class="icon-dialog" :visible.sync="show" @open="open" :before-close="closeForm"
      append-to-body>
      <el-form :size="size" ref="form" :model="form" :rules="rules"
        :label-width="$store.getters.device == 'mobile' ? '90px' : '16%'">
        <el-row>
          <el-col :span="24">
            <el-form-item label="可兑次数" prop="num" required>
              <el-input v-model="form.num" autoComplete="off" clearable placeholder="请输入可兑次数"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="生成数量" prop="gen_num" required>
              <el-input v-model="form.gen_num" autoComplete="off" clearable placeholder="请输入生成数量"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button :size="size" :loading="loading" type="primary" @click="submit">
          <span v-if="!loading">确 定</span>
          <span v-else>提 交 中...</span>
        </el-button>
        <el-button :size="size" @click="closeForm">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  components: {
  },
  props: {
    show: {
      type: Boolean,
      default: false
    },
    size: {
      type: String,
      default: 'small'
    },
  },
  data() {
    return {
      form: {
        gen_num: '',
        num: '',
      },
      loading: false,
      rules: {
      }
    }
  },
  methods: {
    open() {
    },
    submit() {
      this.$refs['form'].validate(valid => {
        if (valid) {
          this.loading = true
          this.$axios.post('/admin/Redemption/adds', this.form).then(res => {
            if (res.data.status == 200) {
              this.$message({ message: res.data.msg, type: 'success' })
              this.$emit('refesh_list')
              this.closeForm()
            } else {
              this.loading = false
              this.$message.error(res.data.msg)
            }
          }).catch(() => {
            this.loading = false
          })
        }
      })
    },
    closeForm() {
      this.$emit('update:show', false)
      this.loading = false
      if (this.$refs['form'] !== undefined) {
        this.$refs['form'].resetFields()
      }
    },
  }
}
</script>

<style  lang="scss">
@import '@/assets/scss/common.scss'
</style>
